import request from '@/utils/request.js'

const api_name = '/ucenter/user/users'

export function userLogin (data) {
  return request({
    url: `${api_name}/login`,
    method: 'post',
    data
  })
}

export function getInfo () {
  return request({
    url: `${api_name}/verify`,
    method: 'get',
  })
}

export function getUserById (id) {
  return request({
    url: `${api_name}/${id}`,
    method: 'get'
  })
}

//用户修改头像
export function updateAvatar (data) {
  return request({
    url: `${api_name}/avatar`,
    method: 'put',
    data
  })
}

//用户取消修改头像
export function cancelUpdateAvatar (data) {
  return request({
    url: `${api_name}/avatar/cancel`,
    method: 'put',
    data
  })
}

//获取短信验证码
export function getSms (data) {
  return request({
    url: `${api_name}/sms`,
    method: 'post',
    data
  })
}

//用户注册
export function register (data) {
  return request({
    url: `${api_name}/register`,
    method: 'post',
    data
  })
}

//检验手机号是否注册
export function checkMobile (mobile) {
  return request({
    url: `${api_name}/check/${mobile}`,
    method: 'get'
  })
}

//检验验证码是否正确
export function checkCode (phone,code) {
  return request({
    url: `${api_name}/sms/${phone}/${code}`,
    method: 'get'
  })
}

//修改密码
export function updatePassword (id,data) {
  return request({
    url: `${api_name}/${id}`,
    method: 'put',
    data
  })
}

//修改个人信息
export function updateUser (id,data) {
  return request({
    url: `${api_name}/info/${id}`,
    method: 'put',
    data
  })
}

//用户注销
export function userLogout (data) {
  return request({
    url: `${api_name}/logout`,
    method: 'post',
    data
  })
}
